/**
 * @Author: oldTea
 * @CreateTime: 2024-11-26
 * @Description: 自定义线程测试CountDownLatch
 * @Version: 1.0
 */
package com.ambition.demo.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

/**
 *@Author: oldTea
 *@CreateTime: 2024-11-26
 *@Description: 自定义线程测试CountDownLatch
 *@Version: 1.0
 */
@Slf4j
public class Worker extends Thread implements Runnable{

    private String name;

    private CountDownLatch latch;

    public Worker(String name,CountDownLatch latch){
        this.name = name;
        this.latch = latch;
    }

    @Override
    public void run() {
        try {
            //模拟线程工作
            log.info("当前线程{}完成任务",name);
        }catch (Exception x){

        }finally {
            latch.countDown();
        }
    }
}


